/*
 *  Copyright 2013 National Institute of Advanced Industrial Science and Technology
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.sss.dummykvs;

import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.List;

import org.sss.mapreduce.DB;
import org.sss.mapreduce.IOConfiguration;
import org.sss.util.Misc;

public class DummyDB implements DB {
  RemoteDB proxy;
  static {
    Misc.setDangerousSecurityManagerToSystem();
  }

  public DummyDB(IOConfiguration conf, String host, int port)
    throws RemoteException, NotBoundException {
    Registry r = LocateRegistry.getRegistry(host, port);
    proxy = (RemoteDB)r.lookup("db");
  }

  @Override
  public void putlist(byte[][] kvs) throws IOException {
    proxy.putlist(kvs);
  }

  @Override
  public List<byte[]> range(byte[] prefix, byte[] sentinel, int limit,
                            boolean binc) throws IOException {
    return proxy.range(prefix, sentinel, limit, binc);
  }

  @Override
  public List<byte[]> ranged(byte[] prefix, byte[] sentinel, int limit,
                             boolean binc) throws IOException {
    return proxy.ranged(prefix,  sentinel, limit, binc);
  }
  @Override
  public int rangeout(byte[] prefix, byte[] sentinel, int count,
                      boolean binc) throws IOException {
    return proxy.rangeout(prefix, sentinel, count, binc);
  }

  @Override
  public List<byte[]> fwmkeys(byte[] prefix, int limit) throws IOException {
    return proxy.fwmkeys(prefix, limit);
  }

  @Override
  public byte[] get(byte[] key) throws IOException {
    return proxy.get(key);
  }

  @Override
  public void close() throws IOException {
    // Do nothing.
  }

  @Override
  public List<byte[]> getlist(byte[][] keys) throws IOException {
    return proxy.getlist(keys);
  }

  @Override
  public void outlist(byte[][] keys) throws IOException {
    proxy.outlist(keys);
  }
}
